/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package vn.edu.vttu;

import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;

/**
 *
 * @author Lucas Nguyen
 */
public class ConnectionServer {
        public static String mailHost = "nhom5.no-ip.org";
        public static String mailStoreType = "pop3";
        public static  String userName   ;
        public static String passWord ;
        
        
        
          public static Session createSessionSMTP(final String username, final String password) {
        Properties props = System.getProperties();
        props.put("mail.smtp.host", ConnectionServer.mailHost);
        props.put("mail.smtp.port", "25");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.auth", "true");
        return Session.getInstance(props, new Authenticator() {

            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });// gữi mail
    }
          
          
          
          
     public static String kiemTraDiaChiGmail(String diaChi) {
        if (diaChi == null || diaChi.isEmpty()) {
            return null;
        }
        diaChi = diaChi.toLowerCase();
        
        if (diaChi.endsWith("@nhom5.no-ip.org")) {
            return diaChi;
        } else {
            if (diaChi.indexOf('@') < 0) {
                return diaChi.concat("@nhom5.no-ip.org");
            }
        }
        return null;
    }
      public String trimspace(String str)
{
    str = str.replaceAll("\\s+", " ");
    str = str.replaceAll("(^\\s+|\\s+$)", "");
    return str;
}
}
